package com.lingz.manager.modules.wuxue.serviceimpl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.lingz.manager.base.DevplatBaseDao;
import com.lingz.manager.modules.wuxue.dao.KeyAreaInfoDao;
import com.lingz.manager.modules.wuxue.mapper.KeyAreaInfoMapper;
import com.lingz.manager.modules.wuxue.entity.KeyAreaInfo;
import com.lingz.manager.modules.wuxue.service.KeyAreaInfoService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Slf4j
@Service
@Transactional
public class KeyAreaInfoServiceImpl implements KeyAreaInfoService {
    @Autowired
    KeyAreaInfoDao keyAreaInfoDao;

    @Autowired
    KeyAreaInfoMapper keyAreaInfoMapper;
    @Override
    public DevplatBaseDao<KeyAreaInfo, String> getRepository() {
        return keyAreaInfoDao;
    }

    @Override
    public List<KeyAreaInfo> findListKeyAreaInfo(KeyAreaInfo opeEntInfo) {
        LambdaQueryWrapper<KeyAreaInfo> wrapper = Wrappers.lambdaQuery(KeyAreaInfo.class);
        List<KeyAreaInfo> list = keyAreaInfoMapper.selectList(wrapper);
        return list;
    }

    @Override
    public KeyAreaInfo findKeyAreaInfoById(int id) {
        return keyAreaInfoMapper.selectById(id);
    }

    @Override
    public List<KeyAreaInfo> findKeyAreaInfoByType(String areaType) {
        LambdaQueryWrapper<KeyAreaInfo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(KeyAreaInfo::getAreaType, areaType);
        wrapper.orderByAsc(KeyAreaInfo::getId);
        return keyAreaInfoMapper.selectList(wrapper);
    }

    @Override
    public Integer findKeyAreaInfoNum(String areaType, String cityName, String townName, String villageName) {
        LambdaQueryWrapper<KeyAreaInfo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(KeyAreaInfo::getAreaType, areaType);
        if (StringUtils.isNotBlank(cityName)) {
            wrapper.eq(KeyAreaInfo::getCityName, cityName);
        }
        if (StringUtils.isNotBlank(townName)) {
            wrapper.eq(KeyAreaInfo::getTownName, townName);
        }
        if (StringUtils.isNotBlank(villageName)) {
            wrapper.eq(KeyAreaInfo::getVillageName, villageName);
        }
        return keyAreaInfoMapper.selectCount(wrapper);
    }


}
